package com.tvein.sanguo.action.controller.menu
{
	//flash
	import flash.display.DisplayObject;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.action.view.ActionMediator;
	import com.tvein.sanguo.action.model.SystemProxy;
	import com.tvein.sanguo.swc.action.menu.MenuShell;
	import com.tvein.sanguo.swc.action.menu.MenuCall;
	import com.tvein.sanguo.swc.action.menu.MenuFunction;
//
	public class ActionMenu extends SimpleFabricationCommand implements ICommand
	{
		private var actionMediator:ActionMediator;
		private var systemData:SystemProxy;
		
		override public function execute(notification:INotification) : void
		{
			actionMediator = facade.retrieveMediator(ActionMediator.NAME) as ActionMediator;
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			clearChild();
			
			var params:Object = new Object();
			
			switch(notification.getBody()[0])
			{
				case "normal":
					var menuShell:MenuShell = new MenuShell();
					actionMediator.action.addChild(menuShell);
					menuShell.name = "MenuShell";
					
					params.Volume = systemData.effectVol;
					menuShell.console("setEffect", params);
					
					menuShell.console("setData", notification.getBody()[1]);
					menuShell.addEventListener("Menu-Shell", actionMediator._handleEvents);
					
					break;
				case "call":
					var menuCall:MenuCall = new MenuCall();
					actionMediator.action.addChild(menuCall);
					menuCall.name = "MenuCall";
					
					params.Volume = systemData.effectVol;
					menuCall.console("setEffect", params);

					menuCall.console("setData", [notification.getBody()[1], notification.getBody()[2]]);
					menuCall.addEventListener("Menu-Call", actionMediator._handleEvents);
					
					break;
				case "function":
					var menuFunction:MenuFunction = new MenuFunction();
					actionMediator.action.addChild(menuFunction);
					menuFunction.name = "MenuFunction";
					
					params.Volume = systemData.effectVol;
					menuFunction.console("setEffect", params);

					menuFunction.addEventListener("Menu-Function", actionMediator._handleEvents);
					
					break;
			}
		}
		
		private function clearChild():void
		{
			for (var i:int = actionMediator.action.numChildren - 1; i >= 0; i--)
			{
				actionMediator.action.removeChildAt(0); 
			}
		}
	}
}